package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.InterveneDao;
import com.itheima.pojo.Repository;
import com.itheima.pojo.Sport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = InterveneService.class)
@Transactional
public class InterveneServiceImpl implements InterveneService{

    @Autowired
    private InterveneDao interveneDao;


    @Override
    public List<Sport> findInterveneByLevelId(Integer levelId) {
        List<Integer> sportids= interveneDao.findSportidsByLevelId(levelId);
        Map<String, Object> map = new HashMap<>();
        List<Sport> sports = new ArrayList<>();
        if (sportids != null && sportids.size() > 0) {
            for (Integer sportid : sportids) {
                Sport sport = interveneDao.findSportById(sportid);
                sports.add(sport);
            }
        }
        return sports;
    }

    @Override
    public List<Repository> findMealByLevelId(Integer levelId) {
        List<Integer> repositoryIds = interveneDao.findRepositoryIdByLevelId(levelId);
        Map<String, Object> map = new HashMap<>();
        List<Repository> repositories = new ArrayList<>();
        if (repositoryIds != null && repositoryIds.size() > 0) {
            for (Integer repositoryId : repositoryIds) {
                Repository repository = interveneDao.findRepositoryById(repositoryId);
                repositories.add(repository);
            }
        }
        return repositories;
    }
}
